package com.ww.basic.namedparameter

object Test01 {

  /**
   * 传名参数
   * 自己实现while循环
   * @param condition
   * @return
   */
  def myWhile(condition: => Boolean): (=> Unit) => Unit = {
    def doLoop(op: => Unit): Unit = {
      if (condition) {
        op
        myWhile(condition)(op)
      }
    }

    doLoop _
  }

  def main(args: Array[String]): Unit = {
    var n = 10
    myWhile(n > 0) {
      println(n)
      n -= 1
    }
  }
}
